<style scoped>
body,uni-page-body{
	height: 100%;
}
.tabListBox{
	flex: 0 0 180rpx;
	height: 100%;
}
</style>
<template>
    <view class="page h-100">
		<view class="pad-0-12">
			<search></search>
		</view>
        <view class="flex align-center h-100 mar-t-10">
			<view class="tabListBox">
				<tab :list="tabList" :tabIndex="tabIndex"></tab>
			</view>
			<swiper class="flex-1 h-100 flex flex-column" @change="changeSwiper" :current="tabIndex">
				<swiper-item class="swiper-item" v-for="(item,index) in tabList" :key="index">
					<list-item :list="listCatchData[index]" :load="load[index]" @listloadmore="listloadmore" @refreshList="refreshList"></list-item>
				</swiper-item>
			</swiper>
		</view>
    </view>
</template>

<script>
import tab from '@/components/tab/tabChild.vue'
import listItem from '@/components/list/list-item-child-home.vue'
import search from '@/components/top-search-child-home.vue'
import {socialHome} from '@/utils/http'
export default {
    data() {
        return {
            tabList:[{
				id:'',
				name:'全部'
			},{
				id:0,
				name:'灵溪镇'
			},{
				id:1,
				name:'桥墩镇'
			},{
				id:2,
				name:'金乡镇'
			},{
				id:3,
				name:'钱库镇'
			},{
				id:4,
				name:'马站镇'
			},{
				id:5,
				name:'钱库镇'
			},{
				id:6,
				name:'马站镇'
			},{
				id:7,
				name:'钱库镇'
			},{
				id:8,
				name:'马站镇'
			}],
			tabIndex:0,
			listCatchData:{
				0:[{
					name:1
				},{
					name:1
				}],
				1:[]
			},
			load:{},
			pageSize:16,
			loading:false,
        }
    },
    components:{
		tab,listItem,search
	},
     computed: {
        
    },
    watch:{
        
    },
	async onLoad(option) {
	    // this.getArea();
	    // await this.getConsultorTags();
	    // await this.weekList();
	    // this.getConsultorList();
	   // this.getList(this.tabIndex)
	},
    methods: {
        changeSwiper(e) {
        	const {
        		current
        	} = e.detail
        	this.tabIndex = current
        	console.log('changeSwiper——this.tabIndex',this.tabIndex)
        	if(!this.listCatchData[this.tabIndex] || this.listCatchData[this.tabIndex].length === 0){
        		this.getList(this.tabIndex)
        	}
        },
        tabClick({data,index}){
        	this.tabIndex = index
        	console.log('tabClick——this.tabIndex',this.tabIndex)
        },
        refreshList(current) {
        	this.listCatchData = {}
        	this.$set(this.listCatchData,current,[])
        	this.load = {}
        	this.getList(current)
        },
        listloadmore(val){
        	if(this.load[this.tabIndex].loading === 'noMore') return
        	this.load[this.tabIndex].page++
        	this.getList(this.tabIndex)
        },
        getList(current) {
        	if(!this.load[current]){
        		this.load[current] = {
        			page:1,
        			loading:'loading'
        		}
        	}
        	const params = {
        		audit_status:current,
        		page:this.load[current].page,
        		num:this.pageSize
        	}
        	if(current==0){
        		delete params.audit_status
        	}
        	console.log('params',params)
        	this.loading = true
        	socialHome(params).then(res => {
        		//如果没数据了
        		if(data&&(data.length === 0 || data.length < this.pageSize)){
        			
        		}
        		let oldList = this.listCatchData[current] || []
        		oldList.push(...data)
        		this.$set(this.listCatchData,current,oldList)
        	}).finally(()=>{
        		this.loading = false
        	})
        },
    },
}
</script>